package com.ele.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebFilter("/*")
public class CorsFilter implements Filter {
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletResponse resp = (HttpServletResponse) servletResponse;
        // 允许哪些域名来访问
        resp.setHeader("Access-Control-Allow-Origin", "*");
        // 允许通过什么请求方式来访问
        resp.setHeader("Access-Control-Allow-Methods", "*");
        // 允许本次请求中携带哪些请求头信息
        resp.setHeader("Access-Control-Allow-Headers", "*");
        filterChain.doFilter(servletRequest,resp);
    }
}
